﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using Wicresoft.Logger;
using Wicresoft.Service.Tasks;

namespace Wicresoft.Service
{
    public partial class CMDBService : ServiceBase
    {
        private IList<ITask> tasklist;

        public CMDBService()
        {
            InitializeComponent();
            tasklist = SchedulerHelper.GetAllTasks().ToArray();
        }

        protected override void OnStart(string[] args)
        {
            System.Threading.Tasks.Parallel.ForEach(tasklist, t =>
            {
                try
                {
                    t.OnStart();
                }
                catch (Exception e)
                {
                    Log.Exception("Scheduler", e);
                }
            });
        }

        protected override void OnStop()
        {
            System.Threading.Tasks.Parallel.ForEach(tasklist, t =>
            {
                try
                {
                    t.OnStop();
                }
                catch (Exception e)
                {
                    Log.Exception("Scheduler", e);
                }
            });
        }
    }
}
